package com.vdm.util;

import java.util.HashMap;
import java.util.Map;

/**
 * 返回值工具
 * @author fuxian
 *
 */
public class ReturnMapUtil {
	public static Map<String, Object> getOKResult() {
		return getOKResult(null);
	}

	/**
	 * 获取成功map
	 * 
	 * @param returnMap
	 * @return
	 */
	public static Map<String, Object> getOKResult(Map<String, Object> returnMap) {
		String [] okMessage = new String[]{"200", "恭喜，操作成功"};
		return setReturnHeader(returnMap, okMessage);
	}

	/**
	 * 获取失败map
	 *
	 * @param error_msg
	 * @return
	 */
	public static Map<String, Object> getErrorResult( String[] error_msg ) {
		return setReturnHeader( null, error_msg );
	}

	/**
	 * 获取失败map
	 * 
	 * @param returnMap
	 * @param error_msg
	 * @return
	 */
	public static Map<String, Object> getErrorResult(
			Map<String, Object> returnMap, String[] error_msg) {
		return setReturnHeader(returnMap, error_msg);
	}


	private static Map<String, Object> setReturnHeader(
			Map<String, Object> bodyMap, String[] error_msg) {
		Map<String, Object> map = new HashMap<>();

		Map<String, Object> headMap = new HashMap<>();
		headMap.put("code", error_msg[0]);
		headMap.put("msg", error_msg[1]);

		if (bodyMap == null) {
			bodyMap = new HashMap<String, Object>();
		}

		map.put("responseHead", headMap);
		map.put("responseBody", bodyMap);

		return map;
	}

}
